var _page = $('.page');

bottlecms.load({
    done: function(page, next) {
        bottlecms.get("/m/ajax/center/friend/newfriend", {
            page: page
        }, function(data) {
            var lis = [];
            for (var o in data.list) {
                lis.push(friend_apply_template(data.list[o]))
            }
            next(lis.join(''), lis.length);
        })
    }
}).init();


// 同意
$(_page).on('click', '.bcui-infinite-list .item .js_agree', function(event) {
    var target_id = $(this).attr('data-id')
    var _this = this;
    bottlecms.confirm("确定同意吗？", function() {
        agree_apply_friend_fun(target_id, function() {
            $(_this).parents(".item").attr('status', 1);
        });
    })
});
// 拒绝
$(_page).on('click', '.bcui-infinite-list .item .js_refuse', function(event) {
    var target_id = $(this).attr('data-id');
    var _this = this;
    bottlecms.confirm("确定拒绝吗？", function() {
        refuse_apply_friend_fun(target_id, function() {
            $(_this).parents(".item").attr('status', 2);
        });
    })
});





/*新朋友列表*/
function friend_apply_template(v) {
    var html = "";
    html += '<div class="item ub ub-ac" status="' + v.isAuth + '">';
    if (v) {
        html += '    <a   class="ub ub-f1 "  href="/single/info/' + v.userId + '">';
        html += '    <div class="ub-img1"  photo_mode="' + v.photoMode + '" style="background-image:url(' + v.photo + '_200x200.jpg)"></div>';
        html += '    <div class="ub-f1 info">';
        html += '        <div class="nickname">' + v.nickname + ' <span class="gender_' + v.gender + '"></span></div>';
        html += '        <p class="info"> ';
        if (v.districtCn) {
            html += '            <span class="district">' + v.districtCn + '</span> ';
        }
        html += '            ' + v.age + '岁 ';
        if (v.height) {
            html += '            . ' + v.height + 'cm ';
        }
        if (v.constellationCn) {
            html += '            . ' + v.constellationCn + ' ';
        }
        html += '        </p>';
        html += '    </div>';
        html += '    </a>';
    } else {
        html += '    <div  class="ub ub-f1 empty">用户不存在或已删除</div>';
    }

    html += '    <div class="btnbox _dc">';
    html += '       <div class="status_3 group-btn group-btn-sm">';
    html += '           <span class="btn btn-info js_agree" data-id="' + v.userId + '">同意</span>';
    html += '           <span class="btn btn-danger js_refuse" data-id="' + v.userId + '">拒绝</span>';
    html += '       </div>';
    html += '       <div class="status_1">已同意</div>';
    html += '       <div class="status_2">已拒绝</div>';
    html += '       <div class="status_4">已超时</div>';
    html += '    </div>';
    html += '</div>';
    return html;
}